<template>
  <div>
    <div class="gl_searchBox gl_mb_15">
      <el-row :gutter="20">
        <el-col :md="6" :lg="4">
          <p>机构名称</p>
          <el-input v-model="QO.DelegationName" placeholder="请输入机构名称" size="mini" clearable @change="getDataList()" />
        </el-col>
        <el-col :md="6" :lg="4">
          <p>联系人</p>
          <el-input v-model="QO.ContactPerson" placeholder="请输入联系人" size="mini" clearable @change="getDataList()" />
        </el-col>
        <el-col :md="6" :lg="4">
          <p>联系方式</p>
          <el-input v-model="QO.PhoneNumber" placeholder="请输入联系方式" size="mini" clearable @change="getDataList()" />
        </el-col>
        <el-col :md="6" :lg="5">
          <p>领队/教练/队医/官员/其他工作人员</p>
          <el-input v-model="QO.Name" placeholder="请输入领队/教练/队医/官员/其他工作人员" size="mini" clearable @change="getDataList()" />
        </el-col>
        <el-col :md="4" :lg="2">
          <!-- 查询按钮 -->
          <el-button style="margin-top:27px" type="primary" size="mini" @click="getDataList()">查询</el-button>
        </el-col>
      </el-row>
    </div>

    <el-table v-loading="loading" :data="tableData" stripe size="mini">
      <el-table-column type="index" width="50" align="center" />
      <el-table-column prop="imagePath" label="头像" width="90" align="center">
        <template slot-scope="{row}">
          <img v-if="row.imagePath" width="40" :src="getStaticFileUrl(row.imagePath)">
          <img v-else width="40" src="@/assets/images/person_default.png">
        </template>
      </el-table-column>
      <el-table-column prop="name" label="机构名称" min-width="200" />
      <el-table-column prop="contactPerson" label="联系人" width="120" align="center" />
      <el-table-column prop="phoneNumber" label="联系方式" width="250" align="center" />
      <el-table-column label="领队 / 教练 / 队医 / 官员 / 其他工作人员" width="340" align="center">
        <template slot-scope="{row}">
          <span v-for="(jtem, jndex) in row.leaderList" :key="'leader' + jndex">{{ jtem.name + ' ' }}</span>
          <span v-if="row.leaderList.length === 0">--</span>
          <span> / </span>
          <span v-for="(item, index) in row.coachList" :key="'coach' + index">{{ item.name + ' ' }}</span>
          <span v-if="row.coachList.length === 0">--</span>
          <span> / </span>
          <span v-for="(item, index) in row.teamDoctorList" :key="'coach' + index">{{ item.name + ' ' }}</span>
          <span v-if="row.teamDoctorList.length === 0">--</span>
          <span> / </span>
          <span v-for="(item, index) in row.OfficerList" :key="'coach' + index">{{ item.name + ' ' }}</span>
          <span v-if="row.OfficerList.length === 0">--</span>
          <span> / </span>
          <span v-for="(item, index) in row.OtherList" :key="'coach' + index">{{ item.name + ' ' }}</span>
          <span v-if="row.OtherList.length === 0">--</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" width="150" fixed="right">
        <template slot-scope="{ row }">
          <el-button size="mini" type="text" @click="clickDel(row)">清除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <!-- <el-row class="gl_pt_20" style="text-align: center;">
      <el-pagination
        :current-page="QO.Page"
        :page-size="QO.MaxResultCount"
        :total="totalPage"
        layout="total,sizes,prev,pager,next,jumper"
        :page-sizes="[10, 20, 50, 100]"
        @size-change="sizeChange"
        @current-change="pageIndexChange"
      />
    </el-row> -->
  </div>
</template>
<script>
import { mapState, mapActions } from 'vuex';
import {
  api_GET_EventsManagementEntryDelegationCompetitionOfficialsCompetitionId, // 获取报名机构下的领队教练
  api_GET_EventsManagementEntryClearOfficials // 清理领队教练
} from '@/extend/api/game.js';
export default {
  props: {
    competitionInfo: {
      type: Object,
      default () {
        return {};
      }
    }
  },
  data() {
    return {
      loading: false,
      athleteLoading: false,
      groupLoading: false,
      projectLoading: false,
      QO: {
        CompetitionId: '',
        DelegationName: '',
        ContactPerson: '',
        PhoneNumber: '',
        Name: ''
      },
      totalPage: 0,
      mechanisms: [], // 所属机构下拉列表
      tableData: []
    };
  },
  computed: {
    ...mapState({
      dict: state => state.dict.dict,
      tenantId: state => state.user.tenantId
    })
  },
  created() {
    this.getDict();
    this.getDataList(); // 获取参赛人员
  },
  methods: {
    ...mapActions({ getDict: 'dict/getDict' }),
    // 查询
    getDataList() {
      var that = this;
      that.loading = true;
      this.QO.CompetitionId = this.$route.params.id;
      api_GET_EventsManagementEntryDelegationCompetitionOfficialsCompetitionId(this.QO).then(res => {
        that.loading = false;
        that.tableData = res || [];
        that.tableData.map((item, index) => {
          const coachList = [];
          const leaderList = [];
          const teamDoctorList = [];
          const OfficerList = [];
          const OtherList = [];
          item.officialResults.map(jtem => {
            if (jtem.registerTagTypeCode === 'Coach') {
              coachList.push(jtem);
            } else if (jtem.registerTagTypeCode === 'Leader') {
              leaderList.push(jtem);
            } else if (jtem.registerTagTypeCode === 'TeamDoctor') {
              teamDoctorList.push(jtem);
            } else if (jtem.registerTagTypeCode === 'Officer') {
              OfficerList.push(jtem);
            } else if (jtem.registerTagTypeCode === 'Other') {
              OtherList.push(jtem);
            }
          });
          that.$set(that.tableData[index], 'coachList', coachList);
          that.$set(that.tableData[index], 'leaderList', leaderList);
          that.$set(that.tableData[index], 'teamDoctorList', teamDoctorList);
          that.$set(that.tableData[index], 'OfficerList', OfficerList);
          that.$set(that.tableData[index], 'OtherList', OtherList);
        });
      }, () => {
        that.loading = false;
        that.$message({ type: 'error', message: error.error.message });
      });
    },
    clickDel (row) {
      const that = this;
      this.$confirm(`您确定要清除${row.name}的报名数据吗？`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          that.loading = true;
          api_GET_EventsManagementEntryClearOfficials({ competitionId: that.$route.params.id, delegationId: row.delegationId }).then(res => {
            that.loading = false;
            that.$message({ type: 'success', message: '操作成功' });
            that.getDataList();
          }, error => {
            that.loading = false;
            const _msg = error.error.message || error.message;
            that.$message({ type: 'error', message: _msg });
          });
        })
        .catch(() => {
        });
    },
    // 图片回显
    getStaticFileUrl(relativeUrl) {
      if (!relativeUrl) return '';
      return WEB_CONFIG.VUE_APP_STATIC_FILE_RUL + relativeUrl;
    }
    // // 分页
    // sizeChange: function(MaxResultCount) {
    //   this.QO.MaxResultCount = MaxResultCount;
    //   this.getDataList();
    // },
    // pageIndexChange(currentPage) {
    //   this.getDataList(currentPage);
    // }
  }
};
</script>

